package wortubung.util;

import java.util.Arrays;
import java.util.Iterator;

public class ImmutableStringList implements Iterable<String> {

	private String[] array;

	public ImmutableStringList(String... strings) {
		this.array = Arrays.copyOf(strings, strings.length);
	}

	public int size() { return array.length; }
	public String get(int idx) { return array[idx]; }
	public String[] toArray() { return Arrays.copyOf(array, array.length); }

	@Override
	public Iterator<String> iterator() {
		return new Iterator<String>() {
			private int index = 0;
			@Override public String next() { return index < array.length ? array[index++] : null; }
			@Override public boolean hasNext() { return index < array.length; }
			@Override public void remove() {}
		};
	}

	public static String[][] toArray(ImmutableStringList[] lists) {
		String[][] ret = new String[lists.length][];
		for (int i=ret.length-1; i>=0; --i)
			ret[i] = lists[i].toArray();
		return ret;
	}
}
